<template>
  <el-dialog title="预警基础信息录入" :visible.sync="dialogVisible" width="25%" :before-close="handleClose">
    <el-form :inline="true" :model="scetion" label-width="100px" class="demo-form-inline">
      <el-form-item label="预警类型">
        <el-select v-model="scetion.warnType" placeholder="请选择">
          <el-option value="1" label="拱顶"></el-option>
          <el-option value="2" label="拱脚"></el-option>
          <el-option value="3" label="周边"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="预警值">
        <el-input v-model="scetion.warnValue"></el-input>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          type="date"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择日期"
          v-model="scetion.createTime"
          style="width: 100%;"
        ></el-date-picker>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="create">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import api from "../../../api";
import qs from "qs";
export default {
  data() {
    return {
      dialogVisible: false,
      scetion: {
        warnType: "",
        warnValue: "",
        warnPhone: "",
        createTime: "",
      },
    };
  },
  mounted() {
    this.$bus.$on("onAddSection", (flag) => {
      this.dialogVisible = flag;
    });
  },
  methods: {
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
    create() {
      api
        .sysWarnsave(qs.stringify(this.scetion))
        .then((res) => {
          if (res.data.code == 2001) {
            this.$message({
              type: "success",
              message: "添加成功!",
            });
            this.dialogVisible = false;
            this.$bus.$emit("onRefreshSyswarn");
          } else {
            this.$message({
              type: "fail",
              message: res.data.message,
            });
            console.log(res.data.message);
          }
        })
        .catch((err) => {});
    },

    onSubmit() {
      console.log("submit!");
    },
  },
};
</script>

<style>
</style>